package com.aqie.appletserver.controller;

import com.aqie.appletserver.redis.MiaoshaKey;
import com.aqie.appletserver.redis.RedisService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class IndexController {
    @Resource
    private RedisTemplate<String, Object> redisTemplate;
    @Autowired
    RedisService redisService;

    @GetMapping
    public String index(){
        return "hello applet";
    }

    @GetMapping("redis")
    public String redis(){
        redisTemplate.opsForValue().set("name","aqie");
        String name = (String)redisTemplate.opsForValue().get("name");
        return "hello applet" + name;
    }

    @GetMapping("redis2")
    public String redis2(){
        redisService.set(MiaoshaKey.getMiaoshaPath,"name","aqie");
        String name = redisService.get(MiaoshaKey.getMiaoshaPath, "name", String.class);
        return "hello applet" + name;
    }
}
